<!DOCTYPE html>
<html lang="en">
<!-- 作者：黄萌 -->

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>欢迎使用猫眼电影后台管理系统</title>
    <link rel="stylesheet" href="./layui/css/layui.css">

    <style>
        .login-container {
            background: gray;
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            display: flex;
            justify-content: center;
            align-items: center;

        }

        .login-container form {
            width: 500px;
            background: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 5px rgba(0, 0, 0, .5);

        }

        .login-container form h1 {
            margin: 1em 0;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="login-container">
        <form class="layui-form" action="">
            <h1>欢迎使用猫眼电影后台管理系统</h1>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-block">
                    <input type="text" name="mobile" lay-verify="required|phone" id="txt_user" lay-vertype="tips"
                        placeholder="请输入手机号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-block">
                    <input type="password" name="pwd" lay-verify="required" lay-vertype="tips" placeholder="请输入密码"
                        autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" type="button" lay-submit="" lay-filter="formDemo">登录</button>
                </div>
            </div>
        </form>
        <script src="./layui/layui.js"></script>
        <script src="./js/jquery-1.12.4.min.js"></script>
        <script src="./js/common.js"></script>
        
        <script>
            // JavaScript代码区域
            // 作者：黄佳
            layui.use(['form'], async function () {
                const form = layui.form;
                //监听提交
                form.on('submit(formDemo)', async function (data) {
                    let obj = data.field;
                    //默认他是管理员获取编号在判断
                    obj.isAdmin = "true";
                    console.log(obj)
                    $.ajax({
                        url: "/api/User/login",
                        method: "post",
                        data: obj,
                        // dataType: "JSON",
                        success: function (data) {
                            if (!data) { // 判断是否有该用户
                                layer.msg('登录失败，账号或密码错误!', {
                                    icon: 2,
                                    time: 1000,
                                })
                            } else {
                                console.log(data)
                                if (data.isAdmin == true) {
                                    layer.msg('登陆成功!', {
                                        icon: 1,
                                        time: 1000
                                    }, function () {
                                        localStorage.setItem("mobile", $("#txt_user").val())
                                        location.href = "./index.html";

                                    })
                                } else {
                                    layer.msg('不是管理员!', {
                                        icon: 2,
                                        time: 1000,

                                    })
                                }
                            }

                        }
                    });
                });

            });


        </script>

</body>



</html>